# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Maintainer: Ray Donnelly <mingw.android@gmail.com>
# Contributor: Renato Silva <br.renatosilva@gmail.com>

_realname=gdk-pixbuf2
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.35.4
pkgrel=1
pkgdesc="An image loading library (mingw-w64)"
arch=('any')
url="http://www.gtk.org"
license=(LGPL2)
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-glib2>=2.37.2"
         "${MINGW_PACKAGE_PREFIX}-jasper"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-libtiff")
options=('emptydirs')
install=${_realname}-${CARCH}.install
source=("https://download.gnome.org/sources/gdk-pixbuf/${pkgver%.*}/gdk-pixbuf-${pkgver}.tar.xz"
        0003-fix-dllmain.patch)
sha256sums=('976c0ce1ec27420aaff9c8d580e3e2f83cadc489e37a878b8f1020c238de59d7'
            '21bd9b2ba1447267c84f1b445cbcf50c62299254856c1c227cc7ba4babc9f27e')

prepare() {
  cd ${srcdir}/gdk-pixbuf-${pkgver}
  patch -p1 -i "${srcdir}"/0003-fix-dllmain.patch

  autoreconf -fi
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  mkdir -p docs/reference/gdk-pixbuf/html
  cp -rf ../gdk-pixbuf-${pkgver}/docs/reference/gdk-pixbuf/html/* docs/reference/gdk-pixbuf/html

  ../gdk-pixbuf-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --enable-introspection \
    --enable-relocations \
    --with-included-loaders
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"

  #get rid of "_utf8" sufix in function names
  sed -i 's/\(<constructor\|method name="\)\(.*\)\(_utf8"\)/\1\2"/' gdk-pixbuf/GdkPixbuf-2.0.gir
  g-ir-compiler gdk-pixbuf/GdkPixbuf-2.0.gir > gdk-pixbuf/GdkPixbuf-2.0.typelib

  make DESTDIR="${pkgdir}" install
  mkdir -p ${pkgdir}${MINGW_PREFIX}/lib/gdk-pixbuf-2.0/2.10.0/loaders
  install -Dm644 "${srcdir}/gdk-pixbuf-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
